package AcervoDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import Exceptions.ItemException;
import Model.Item;
import ServicosDAO.ConexaoDAO;

public class ItemDAO {

	public boolean adicionarItem(Item item) {

		String sql = "insert into acervo values('" + item.getId_item() + "','"
				+ item.getDataSystem() + "','true')";

		Connection conexao = new ConexaoDAO().getConnection();

		int ok = 0;

		try {

			PreparedStatement stmt = conexao.prepareStatement(sql);

			ok = stmt.executeUpdate();

			stmt.close();
			conexao.close();

			if (ok == 1) {
				return true;
			}

		} catch (SQLException e) {

			throw new ItemException(e);

		}
		return false;
	}




	public boolean atualizarItem(boolean is_disponivel) {

		String sql = "update item set is_disponivel='" + is_disponivel + "'";

		Connection conexao = new ConexaoDAO().getConnection();

		int ok = 0;

		try {

			PreparedStatement stmt = conexao.prepareStatement(sql);

			ok = stmt.executeUpdate();

			stmt.close();
			conexao.close();

			if (ok == 1) {
				return true;
			}

		} catch (SQLException e) {

			e.printStackTrace();
			throw new RuntimeException();

		}
		return false;
	}

}
